package com.sike.javacore.serializer.hessian;

import com.caucho.hessian.io.HessianInput;
import com.caucho.hessian.io.HessianOutput;
import com.sike.javacore.serializer.hessian.dto.Student;
import com.sike.javacore.serializer.hessian.dto.SubStudent;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;

public class Hessian03Test {
    public static void main(String[] args) throws IOException {
        SubStudent subStudent = new SubStudent();
        subStudent.setName("李四");
        subStudent.setHeight(185);
        subStudent.setSubValue("lisi");
        subStudent.setGender("男");

        // 序列化
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        HessianOutput hessianOutput = new HessianOutput(bos);
        hessianOutput.writeObject(subStudent);

        //反序列化
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        HessianInput hessianInput = new HessianInput(bis);
        SubStudent student2 = (SubStudent) hessianInput.readObject();
        System.out.println("反序列化内容：" + student2);
    }
}
